<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回字符集的名称</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.mysql-affected-rows.html">« mysql_affected_rows</a></li>
      <li style="float: right;"><a href="function.mysql-close.html">mysql_close »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.mysql.html">MySQL 函数</a></li>
    <li>返回字符集的名称</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mysql-client-encoding" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysql_client_encoding</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_client_encoding</span> &mdash; <span class="dc-title">返回字符集的名称</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mysql-client-encoding-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mysql_client_encoding</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code><span class="initializer"> = ?</span></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   从 MySQL 中取得 <code class="literal">character_set</code> 变量的值。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysql-client-encoding-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    <dt>

<code class="parameter">link_identifier</code></dt>
<dd>
<p class="para">MySQL
连接。如不指定连接标识，则使用由 <span class="function"><a href="function.mysql-connect.html" class="function">mysql_connect()</a></span>
最近打开的连接。如果没有找到该连接，会尝试不带参数调用
<span class="function"><a href="function.mysql-connect.html" class="function">mysql_connect()</a></span>
来创建。如没有找到连接或无法建立连接，则会生成
<strong><code>E_WARNING</code></strong> 级别的错误。</p></dd>


   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-client-encoding-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回当前连接的默认字符集名称。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysql-client-encoding-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1740">
    <p><strong>示例 #1 <span class="function"><strong>mysql_client_encoding()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_user'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_password'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$charset&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_client_encoding</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"The&nbsp;current&nbsp;character&nbsp;set&nbsp;is:&nbsp;</span><span style="color: #0000BB">$charset</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
The current character set is: latin1
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-client-encoding-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">本扩展自 PHP 5.5.0
起已废弃，并在自 PHP 7.0.0 开始被移除。应使用 <a href="book.mysqli.html" class="link">MySQLi</a>
或 <a href="ref.pdo-mysql.html" class="link">PDO_MySQL</a> 扩展来替换之。参见 <a href="mysqlinfo.api.choosing.html" class="link">MySQL：选择 API</a> 
指南来获取更多信息。用以替代本函数的有：</p>
   <p class="para">
    <ul class="simplelist">
     <li class="member"><span class="function"><a href="mysqli.character-set-name.html" class="function">mysqli_character_set_name()</a></span></li>
     <li class="member"><span class="methodname"><a href="pdo.setattribute.html" class="methodname">PDO::setAttribute()</a></span> (e.g., <code class="literal">$db-&gt;setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, &quot;SET NAMES &#039;utf8&#039;&quot;);</code>)</li>
    </ul>
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysql-client-encoding-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mysql-real-escape-string.html" class="function" rel="rdfs-seeAlso">mysql_real_escape_string()</a> - 转义 SQL 语句中使用的字符串中的特殊字符，并考虑到连接的当前字符集</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>